﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DYSmartNetServer;

namespace TestServer
{
    class Program
    {
        static DYNet con;

        static void Main(string[] args)
        {
            con = new DYNet(true);
            con.StartServer(true, 4504);
            DYNet.OnConnectEvent += new OnConnectDelegate(DYNet_OnConnectEvent);
            DYNet.OnDataEvent += new OnDataDelegate(DYNet_OnDataEvent);
            DYNet.ClientExitEvent += new ClientExitDelegate(DYNet_ClientExitEvent);
            Console.WriteLine("DY SmartNet Server is run!");
            Console.Read();
        }

        static void DYNet_OnConnectEvent(byte[] data, DYtoken CurrentClient)
        {
            if (con.AddClient(CurrentClient) == AddResult.Added)
            {
                con.ConnectReCall(data, CurrentClient);
            }
        }

        static void DYNet_OnDataEvent(byte[] data, DYtoken CurrentClient)
        {
            con.SendToAll(data);
        }

        static void DYNet_ClientExitEvent(string SessionId)
        {
            con.DelClient(SessionId);
        }

    }
}
